import json

import requests
import hashlib

# --------------------登录------------------
username='wang01'
password='123456'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用方法hexdigest()加密
# 构造请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
    'Content-Type': 'application/json;charset=UTF-8'
}
#构造url
url_base=r'http://192.168.92.128:3000/'
url_login= url_base+r'/jshERP-boot/user/login'
#构造数据
data_login={"loginName":username,"password":password_md5}
#发送请求
resp=requests.post(url_login,json=data_login,headers=headers)
#获取响应
print(resp.text)
token=resp.json()['data']['token']
print('token：'+token)
# -------------------角色管理：新增------------------
# name='jiaose01'
# type='全部数据'
# #构造请求头
# headers['X-Access-Token']=token
# #构造url
# url_role_add=url_base+r'/jshERP-boot/role/add'
# #构造数据
# data_role_add = {"name":name,"type":type}
# #发送请求
# resp=requests.post(url_role_add,json=data_role_add,headers=headers)
# #获取响应
# # print(resp.text)
# message=resp.json()['data']['message']
# print(f'角色新增{message}')
# # -------------------角色管理：编辑------------------
# deleteFlag="0"
# enabled='true'
# id=32
# name="jiaose02"
# tenantId=63
# type="全部数据"
# #构造请求头
# headers['X-Access-Token']=token
# #构造url
# url_role_update=url_base+r'/jshERP-boot/role/update'
# #构造数据
# data_role_update={"deleteFlag":deleteFlag,"enabled":enabled,"id":id,"name":name,"tenantId":tenantId,"type":type}
# #发送请求
# resp=requests.put(url_role_update,json=data_role_update,headers=headers)
# #获取响应
# # print(resp.text)
# message=resp.json()['data']['message']
# print(f'角色修改{message}')
#  -------------------角色管理：删除------------------
# id=30
# #构造请求头
# headers['X-Access-Token']=token
# #url
# url_role_delete=url_base+r'/jshERP-boot/role/delete'
# #数据
# data_role_delete={'id':id}
# resp=requests.delete(url_role_delete,params=data_role_delete,headers=headers)
# #获取响应
# # print(resp.text)
# message=resp.json()['data']['message']
# print(f'角色删除{message}')
#  -------------------角色管理：查询------------------
# name = 'jiaose02'
# description = ''
# #构造请求头
# headers['X-Access-Token']=token
# #url
# url_role_query=url_base+r'/jshERP-boot/role/list'
# #数据
# search_dict={"name":name,"description":description }
# search_str=json.dumps(search_dict)
# data_role_query={
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id','','','action','name','type','priceLimitStr','description','sort','enabled'],
#     'currentPage':1,
#     'pageSize': 10
# }
# resp=requests.get(url_role_query,params=data_role_query,headers=headers)
# #获取响应
# # print(resp.text)
# message=resp.json()['data']['message']
# print(f'查询{message}')
#  -------------------零售管理(出库)：查询------------------
# number=''
# materialParam='口红'
# type='出库'
# subType='零售'
# roleType='全部数据'
# organId=''
# depotId=''
# creator=''
# accountId=''
# status=''
# remark=''
# #构造请求头
# headers['X-Access-Token']=token
# #url
# url_role_query=url_base+r'/jshERP-boot/depotHead/list'
# #数据
# search_dict={"number":number,"materialParam":materialParam,"type":type,"subType":subType,"roleType":roleType,"organId":organId,"depotId":depotId,"creator":creator,"accountId":accountId,"status":status,"remark":remark}
# search_str=json.dumps(search_dict)
# data_role_query={
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id','','action','organName','number','materialsList','operTimeStr','userName','materialCount','totalPrice','getAmount','backAmount','status'],
#     'currentPage':1,
#     'pageSize': 10
# }
# resp=requests.get(url_role_query,params=data_role_query,headers=headers)
# #获取响应
# print(resp.text)
# message=resp.json()['data']['message']
# print(f'查询{message}')

#  -------------------零售管理（出库）：新增------------------
# number='LSCK000000008293'
# defaultNumber='LSCK0000000082923'
# # 构造请求头
# headers['X-Access-Token']=token
# url_depotHead_add=url_base+r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# search_dict={
#         "organId":60,
#         "operTime":'2024-01-12 11:24:07',
#         "number":number,
#         "payType":"预付款",
#         "changeAmount":"5.00",
#         "getAmount":"5.00",
#         "backAmount":0,
#         "accountId":17,
#         "type":"出库",
#         "subType":"零售",
#         "defaultNumber":defaultNumber,
#         "totalPrice":5,
#         "fileName":"",
#         "status":1
# }
# search_str=json.dumps(search_dict)
# data_depotHead_add={
# "info":search_str,
#  "rows":"[{"
#         "\"id\":\"17050298477100851432\","
#         "\"name\":\"口红配件\","
#         "\"standard\":\"个\","
#         "\"model\":null,"
#         "\"color\":\"黑色\","
#         "\"materialOther\":\"\","
#         "\"stock\":-30,"
#         "\"unit\":\"个\","
#         "\"snList\":\"\","
#         "\"batchNumber\":\"\","
#         "\"expirationDate\":\"\","
#         "\"sku\":\"\","
#         "\"operNumber\":1,"
#         "\"unitPrice\":5,"
#         "\"allPrice\":5,"
#         "\"remark\":\"\","
#         "\"orderNum\":1,"
#         "\"depotId\":\"14\","
#         "\"barCode\":\"1020\"}]"
# }
# resp=requests.post(url_depotHead_add,json=data_depotHead_add,headers=headers)
# #获取响应
# print(resp.text)
# msg=resp.json()['msg']
# print(f'添加{msg}')

#  -------------------零售管理（出库）：查看------------------
# number='LSCK000000008293'
# # 构造请求头
# headers['X-Access-Token']=token
# #url地址
# url_depotHead_see=url_base+r'/jshERP-boot/depotHead/getDetailByNumber'
# #数据
# data_depotHead_see={'number':number}
# resp=requests.get(url_depotHead_see,params=data_depotHead_see,headers=headers)
# #响应
# # print(resp.text)
# msg=resp.json()['data']['id']
# print(f'订单id为{msg}')
#  -------------------零售管理（出库）：修改------------------
# # 构造请求头
# headers['X-Access-Token']=token
# #url地址
# url_depotHead_update=url_base+r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# #数据
# search_dict={"id":1204,"type":"出库","subType":"零售","defaultNumber":"LSCK00000017","number":"LSCK00000017",
#        "createTime":"2023-12-15T08:31:10.000+0000","operTime":"2023-12-13 16:13:56","organId":60,"creator":152,
#        "accountId":17,"changeAmount":5,"backAmount":0,"totalPrice":5,"payType":"预付款","billType":'',
#        "remark":'',"fileName":"","salesMan":'',"accountIdList":'',"accountMoneyList":'',"discount":'',
#        "discountMoney":'',"discountLastMoney":0,"otherMoney":'',"deposit":0,"status":"0","purchaseStatus":"0",
#        "source":"0","linkNumber":'',"tenantId":63,"deleteFlag":"0","projectName":'',"organName":"12312666",
#        "userName":'',"accountName":"账户1","allocationProjectName":'',"materialsList":"口红配件 个 ",
#        "salesManStr":'',"operTimeStr":"2023-12-13 16:13:56","finishDebt":'',"depotHeadType":"零售出库",
#        "creatorName":"cheng","contacts":"假睫毛会员","telephone":"13000000000","address":"","finishDeposit":'',
#        "needDebt":'',"debt":-5,"materialCount":'',"hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":'',
#         "getAmount":5}
# search_str=json.dumps(search_dict)
# data_depotHead_update={
# "info":search_str,
# "rows":"[{\"id\":\"1625\",\"name\":\"口红配件\",\"standard\":\"个\",\"model\":\"\",\"color\":\"黑色\",\"materialOther\":\"\",\"stock\":\"305\",\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"1\",\"unitPrice\":\"5\",\"allPrice\":\"5\",\"remark\":\"\",\"orderNum\":1,\"depotId\":\"18\",\"barCode\":\"1020\"}]"
# }
# resp=requests.put(url_depotHead_update,json=data_depotHead_update,headers=headers)
# #响应
# print(resp.text)
# msg=resp.json()['msg']
# print(f'修改{msg}')
#  -------------------零售管理（出库）：复制------------------
# defaultNumber='LSCK00000000834'
# number='LSCK00000000834'
# #  构造请求头
# headers['X-Access-Token']=token
# #url地址
# url_copy=url_base+r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# #数据
# search_dict={"accountId":17,"accountName":"账户1","backAmount":0,"changeAmount":15,"createTime":1705043233000,
#        "creator":63,"debt":-15,"defaultNumber":defaultNumber,"deleteFlag":"0","deposit":"",
#        "discountLastMoney":0,"fileName":"","finishDeposit":0,"hasBackFlag":False,"hasFinancialFlag":False,
#        "id":"","materialCount":1,"materialsList":"衣服  ","number":number,
#        "operTime":"2024-01-12 16:07:23","operTimeStr":"2024-01-12 15:07:05","payType":"现付","purchaseStatus":"0",
#        "source":"0","status":"0","subType":"零售","tenantId":"","totalPrice":15,"type":"出库",
#        "userName":"测试用户","linkNumber":"","billType":"","getAmount":15
#               }
# search_str=json.dumps(search_dict)
# data_copy={
# "info":search_str,
# "rows":"[{\"id\":\"1624\",\"name\":\"衣服\",\"standard\":\"\",\"model\":\"\",\"color\":\"\",\"materialOther\":\"\",\"stock\":\"-1\","
#        "\"unit\":\"件\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"橙色,M\",\"operNumber\":\"1\","
#        "\"unitPrice\":\"15\",\"allPrice\":\"15\",\"remark\":\"\",\"orderNum\":1,\"depotId\":\"14\",\"barCode\":\"1014\"}]"
# }
# resp=requests.post(url_copy,json=data_copy,headers=headers)
# #响应
# # print(resp.text)
# msg=resp.json()['msg']
# print(f'复制{msg}')
#  -------------------零售管理（出库）：删除------------------
# id=1224
# #  构造请求头
# headers['X-Access-Token']=token
# #url地址
# url_depotHead_delete=url_base+r'/jshERP-boot/depotHead/delete'
# #数据
# data_delete={'id':id}
# resp=requests.delete(url_depotHead_delete,params=data_delete,headers=headers)
# print(resp.text)
# message=resp.json()['data']['message']
# print(f'删除{message}')